package hongbao;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * 抢红包
 * 
 * @author Administrator
 * @date 2018/02/07
 */
public class SnatchHongbao {
    public static void getMoney(List<Double> list, Integer remainSize, Double remainMoney) {
        if (remainSize == 1) {
            remainSize--;
            list.add((double)Math.round(remainMoney * 100) / 100);
        } else {
            Random r = new Random();
            double min = 0.01;
            double max = remainMoney / remainSize * 2;
            double money = r.nextDouble() * max;
            money = money < min ? min : money;
            money = Math.floor(money * 100) / 100;
            remainSize--;
            remainMoney -= money;
            list.add(money);
            getMoney(list, remainSize, remainMoney);
        }
    }

    public static double getMoney(Integer remainSize, Double remainMoney) {
        if (remainSize == 1) {
            remainSize--;
            return (double)Math.round(remainMoney * 100) / 100;
        } else {
            Random r = new Random();
            double min = 0.01;
            double max = remainMoney / remainSize * 2;
            double money = r.nextDouble() * max;
            money = money < min ? min : money;
            money = Math.floor(money * 100) / 100;
            remainSize--;
            remainMoney -= money;
            return money;
        }
    }

    public static void main(String[] args) {
        List<Double> list = new ArrayList<Double>();
        getMoney(list, 30, 550.0);
        for (Double double1 : list) {
            System.out.print(double1 + "  ");
        }
    }
}
